//
//  IWBadgeButton.m
//  7期微博
//
//  Created by teacher on 14-8-17.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import "IWBadgeButton.h"



@implementation IWBadgeButton

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundImage:[UIImage imageNamed:@"tabbar_badge"] forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont systemFontOfSize:10];
        self.userInteractionEnabled = NO;
        self.adjustsImageWhenDisabled = NO;
        CGRect rect = self.frame;
        rect.size = self.currentBackgroundImage.size;
        self.frame = rect;
        
    }
    return self;
}

- (void)setItem:(EFengAndETongTabBarItem *)item
{
    _item = item;
    
    // 1.设置提醒数字
    NSInteger newCount = item.badgeValue.integerValue;
    if (newCount > 0) {
        // 需要显示提示按钮
        self.hidden = NO;
        
        if (newCount < 100) {
            NSString * newCountStr = [NSString stringWithFormat:@"%zd", newCount];
            [self setBackgroundImage:[UIImage imageNamed:@"tabbar_badge"] forState:UIControlStateNormal];
            [self setTitle:newCountStr forState:UIControlStateNormal];
        }else
        {
            [self setBackgroundImage:[UIImage imageNamed:@"back-remindRectangle"] forState:UIControlStateNormal];
            [self setTitle:@"99+" forState:UIControlStateNormal];
        }
    }else
    {
        self.hidden = YES;
    }
}

@end
